﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FastReport;
using MINERP.BLL.Statistics.NM;
using MINERP.MODEL.FoundationModel;

namespace MINERP.Statistics.Forms
{
    public partial class FrmShopProductPriceForFuji : Form
    {
        public FrmShopProductPriceForFuji()
        {
            InitializeComponent();
        }
        private static FrmShopProductPriceForFuji instance = null;
        public static FrmShopProductPriceForFuji Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new FrmShopProductPriceForFuji();
                }
                if (instance.IsDisposed)
                {
                    instance = new FrmShopProductPriceForFuji();
                }
                return instance;
            }
        }
        NMShopPruductPriceBll _bll=new NMShopPruductPriceBll();
        

        private void FrmShopProductPrice_Load(object sender, EventArgs e)
        {

        }

        private void textBoxSimCode_KeyDown(object sender, KeyEventArgs e)
        {
            if(e.KeyValue==(int)Keys.Enter)
            {
                List<Shop_Info> list = _bll.GetShopBySimpleCode(textBoxSimCode.Text.Trim());
                cmbShopList.DataSource = list;
                cmbShopList.DisplayMember = "ShopName";
                cmbShopList.ValueMember = "ShopId";

            }
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            Shop_Info shop = (Shop_Info) cmbShopList.SelectedItem;
            if(shop!=null)
            {
                DateTime startTime = Convert.ToDateTime(dateEditStartTime.Text);
                DateTime endTime = Convert.ToDateTime(dateEditEndTime.Text);
               DataSet set= _bll.GetProductPriceDetailForFuji(shop.ShopId, startTime.Date, endTime.Date);
               set.WriteXml(@"C:\windows\xmlData\ShopProductPriceForFuji.xml", XmlWriteMode.WriteSchema);
               Report fasrReport = new Report();
               fasrReport.Preview = previewControl1;
               fasrReport.Load(Application.StartupPath + "\\Report\\ShopProductPriceForFuji.frx");
              


               fasrReport.SetParameterValue("ParaShopName", shop.ShopName);
               fasrReport.SetParameterValue("ParaStartTime", startTime.ToString());
               fasrReport.SetParameterValue("ParaEndTime", endTime.ToString());
               previewControl1.Refresh();
               previewControl1.Show();
               fasrReport.Show();
            }

            this.Cursor = Cursors.Default;
        }

        private void FrmShopProductPrice_FormClosing(object sender, FormClosingEventArgs e)
        {
            instance = null;
        }
    }
}
